package com.slkj.shilixiaoyuanapp.ui.common.adapter;

import android.content.Context;
import android.support.annotation.Nullable;
import android.view.View;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.slkj.shilixiaoyuanapp.R;
import com.slkj.shilixiaoyuanapp.entity.FileEntity;
import com.slkj.shilixiaoyuanapp.util.UpdataFileUtil;

import java.util.ArrayList;
import java.util.List;

/**
 * Created  on 2018-07-23
 *
 * @author 唐开阔
 * @describe
 */
public class FileAdapter extends BaseQuickAdapter<FileEntity, BaseViewHolder> {
    private Context context;
    private ArrayList<FileEntity> filePaths = new ArrayList<>();
    //是否可以删除
    private boolean isCanDelete = true;

    public FileAdapter(Context context, @Nullable ArrayList<FileEntity> filePaths, boolean isCanDelete) {
        super(R.layout.item_chose_file, filePaths);
        this.context = context;
        this.filePaths = filePaths;
        this.isCanDelete = isCanDelete;
    }

    public FileAdapter(Context context, @Nullable ArrayList<FileEntity> filePaths) {
        super(R.layout.item_chose_file, filePaths);
        this.context = context;
        this.filePaths = filePaths;
    }
    public FileAdapter(Context context, @Nullable List<FileEntity> filePaths,boolean isCanDelete) {
        super(R.layout.item_chose_file, filePaths);
        this.context = context;
        this.filePaths.addAll(filePaths);
        this.isCanDelete = isCanDelete;
    }

    @Override
    protected void convert(BaseViewHolder helper, FileEntity item) {
        helper.setText(R.id.tv_name, item.getName())
                .setText(R.id.tv_size, item.getFileSize())
                .setOnClickListener(R.id.img_delete,v -> {
                    filePaths.remove(helper.getAdapterPosition());
                    notifyItemRemoved(helper.getAdapterPosition());
                });


    }


}
